package zjh_20230330;

import java.io.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.LinkedList;
import java.util.stream.Stream;

public class practise01 {
    public static void main(String[] args) {

        try (FileReader fileReader = new FileReader("D:\\kaifamiao\\io-text\\practise-01.txt");
             BufferedReader bufferedReader = new BufferedReader(fileReader)) {

            String s;
            ArrayList<String> list = new ArrayList<>();
            while ((s = bufferedReader.readLine()) != null) {
                list.add(s);
            }

            Collections.sort(list);

            FileWriter fileWriter = new FileWriter("D:\\kaifamiao\\io-text\\practise-01-1.txt");
            BufferedWriter bufferedWriter = new BufferedWriter(fileWriter);

            for (String l : list) {
                System.out.println(l);
                bufferedWriter.write(l);
                bufferedWriter.newLine();
            }
            bufferedWriter.close();

        } catch (FileNotFoundException e) {
            throw new RuntimeException("没有找到文件!");
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
